/**
 * Created with IntelliJ IDEA.
 * Description:前台进程和后台进程
 * User: lenovo
 * Date: 2022-09-05
 * Time: 8:22
 */
public class Demo7 {
    public static void main(String[] args) {
       Thread thread = new Thread(()->{
           while (true){
               System.out.println("hello thread");
               try {
                   Thread.sleep(1_000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
           }

       },"这是我的多线程");
       //将thread进程设置为后台进程
        //必须在start启动前设置,调用start之后就无法在设置为后台进程
       thread.setDaemon(true);//main进程结束后,thread是后台进程,所以thread进程会自动结束
       thread.start();
        System.out.println("main线程执行结束");//这里线程默认是前台进程,即使是main线程结束,thread进程默认是前台进程,前台进程会阻止进程退出,所以thread进程不会就结束
    }
}
